package wt.hpad.activity.cart;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.daimajia.swipe.util.Attributes;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import wt.hpad.ConstantFields;
import wt.hpad.R;
import wt.hpad.base.BaseFragment;
import wt.hpad.model.adapter.DishCartAdapter;
import wt.hpad.utils.RCViewUtil;

/**
 * Created by wt on 12.25.
 */

public class CartFragment extends BaseFragment implements CartContract.View {
    @BindView(R.id.rv_cart)
    RecyclerView rvDetail;
    @BindView(R.id.btn_place_cart)
    TextView btnPlace;

    Unbinder unbinder;
    CartContract.Presenter mCartPresenter;
    private DishCartAdapter mAdapter;

    @Override
    public void setPresenter(CartContract.Presenter presenter) {
        mCartPresenter = presenter;
    }

    @Override
    public void closeCurrentActivity() {
        getActivity().finish();
    }

    @Override
    public void startOrderActivity() {
    }

    @Override
    public View initViews() {
        View view = LayoutInflater.from(baseActivity).inflate(R.layout.cart_frag, null);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void initData() {
        RCViewUtil.init_LinearLayout(rvDetail);
        mAdapter = new DishCartAdapter(getActivity(), ConstantFields.CART_CURRENT, getContext());
        mAdapter.setMode(Attributes.Mode.Single);
        rvDetail.setAdapter(mAdapter);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }


    // "下单"操作
    @OnClick(R.id.btn_place_cart)
    public void onViewClicked() {
        // "双确认"
        mCartPresenter.placeOrder(getActivity());
    }

}